package com.yndsoft.jc.supplier.info;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.yndsoft.jc.R;
import com.yndsoft.jc.supplier.base.SupplierBaseActivity;
import com.yndsoft.jc.supplier.model.AccountModel;
import com.yndsoft.jc.supplier.utils.Constants;

import org.greenrobot.eventbus.EventBus;

public class PayWay extends SupplierBaseActivity implements View.OnClickListener {

    private TextView wayAuto;
    private TextView wayLabour;
    private int payStatus = 1; // 1 自动收款 2 人工申请

    @Override
    public int getContentResId() {
        return R.layout.supplier_pay_way;
    }

    public static void start(Context context, int status) {
        Intent intent = new Intent(context, PayWay.class);
        intent.putExtra(Constants.STATUS, status);
        context.startActivity(intent);
    }

    @Override
    public void initView() {

        ImageButton wayClose = findViewById(R.id.way_close);
        wayAuto = findViewById(R.id.way_auto);
        wayLabour = findViewById(R.id.way_labour);
        Button wayConfirm = findViewById(R.id.way_confirm);

        wayClose.setOnClickListener(this);
        wayAuto.setOnClickListener(this);
        wayLabour.setOnClickListener(this);
        wayConfirm.setOnClickListener(this);
    }

    @Override
    public void initData() {
        switch (getIntent().getIntExtra(Constants.STATUS, 1)) {
            case 1:
                payStatus = 1;
                isCheck(wayAuto, true);
                isCheck(wayLabour, false);
                break;
            case 2:
                payStatus = 2;
                isCheck(wayAuto, false);
                isCheck(wayLabour, true);
                break;
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.way_close:
                finish();
                break;
            case R.id.way_auto:
                payStatus = 1;
                isCheck(wayAuto, true);
                isCheck(wayLabour, false);
                break;
            case R.id.way_labour:
                payStatus = 2;
                isCheck(wayAuto, false);
                isCheck(wayLabour, true);
                break;
            case R.id.way_confirm:
                finish();
                AccountModel model = new AccountModel();
                model.setStatus(payStatus);
                model.setFunction(2);
                EventBus.getDefault().post(model);
                break;
        }
    }

    private void isCheck(TextView textView, boolean isCheck) {
        Drawable drawable;
        if (isCheck) {
            drawable = getResources().getDrawable(R.mipmap.checked);

        } else {
            drawable = getResources().getDrawable(R.mipmap.unchecked);
        }
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        textView.setCompoundDrawables(drawable, null, null, null);
    }
}
